package com.legleg.servlet;

import com.legleg.data.json.AlbumDetailBean;
import com.legleg.handler.AlbumHandler;
import com.legleg.util.BaseUtil;
import com.legleg.util.RequestUtil;
import net.sf.json.JSONObject;
import org.apache.velocity.Template;
import org.apache.velocity.context.Context;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 12-12-27
 * Time: 上午11:35
 * To change this template use File | Settings | File Templates.
 */
public class Album extends BaseServlet {
    @Override
    protected Template execute(HttpServletRequest request, HttpServletResponse response, Context ctx) {
        long id = RequestUtil.getLong(request, "id", -1);
        if (id > -1) {
            com.legleg.data.Album album = AlbumHandler.getInstance().findById(id);
            if (album != null) {
                AlbumDetailBean bean = new AlbumDetailBean(album.getId(), album.getTitle(), album.getTags(), album.getCategory(), BaseUtil.getAlbumAllPics(album.getId(), album.getPicnum()));
                JSONObject json = JSONObject.fromObject(bean);
                ctx.put("json", json.toString());
            }
        }
        return getTemplate("album.vm");
    }
}
